<?php

//require_once('site_config.php');

function audit_log($name,$msg){
  global $site_global_config;
  
  $log_path = $site_global_config['LOG'];
  
  $date = date('Ymd');
  $time = date('H:i:s');
  $dirname = $log_path.'audit/';
	if (!file_exists($dirname)){
	  mkdir($dirname, 0775, true);  # recursive create directory
	  chmod($dirname, 0775); 
  }
	$path = $dirname.$date.'_'.$name.'.log';     	
	
	
	audit_append_to_file2($path, "$time\t$msg\n");
}


# private
function audit_append_to_file2($filename, $filecontent){
  
  if(file_exists($filename)){
    $fh = fopen($filename, 'a') or die("audit_append_to_file2 append: can't open file: $filename");// ??? fixme
    fwrite($fh, $filecontent);
    fclose($fh);
  } else {    
    WriteFile($filename, $filecontent);
  }
}
?>
